package com.demo6.controller;

import com.demo6.pojo.Student;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/student")
public class studentcontroller {
    //获取所有学生信息
    @RequestMapping("/getstus")
    public ModelAndView getstus(){
        //创建第一位学生对象
        Student s1 = new Student();
        s1.setSno("001");
        s1.setSname("李四");
        s1.setSage(20);
        s1.setSgender("男");
        //创建第二位学生对象
        Student s2 = new Student();
        s2.setSno("002");
        s2.setSname("刘英");
        s2.setSage(21);
        s2.setSgender("女");
        //创建第三位学生对象
        Student s3 = new Student();
        s3.setSno("003");
        s3.setSname("王武");
        s3.setSage(23);
        s3.setSgender("男");
        //创建ModelAndView
        ModelAndView mv = new ModelAndView();
        //创建集合
        List<Student> students = new ArrayList<Student>();
        //将学生放到集合里边
        students.add(s1);
        students.add(s2);
        students.add(s3);
        //将集合添加到ModelAndView对象
        mv.addObject("students", students);
        mv.setViewName("stuinfo");
        return mv;
    }
}
